<template>
  <div class="app-main-container">
    <QueryForm
      v-model="filters"
      :query-form-config="queryFormConfig"
      @handleQuery="getList(1)"
      @clear="clearList"
    />
    <el-table
      ref="table"
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      :header-row-class-name="'table-header'"
      class="doumee-element-table"
    >
      <el-table-column
        align="center"
        :label="translate('loginPhone')"
        min-width="140"
        prop="userPhone"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="translate('loginZhangh')"
        min-width="140"
        prop="userAdmin"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="translate('loginName')"
        prop="userName"
        min-width="140"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="translate('loginTime')"
        prop="loginTime"
        min-width="160"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="translate('loginStatus')"
        min-width="110"
        prop="type"
      >
        <template slot-scope="scope">
          {{
            scope.row.status == "1"
              ? translate("loginErr")
              : translate("loginScs")
          }}
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        :label="translate('loginInfo')"
        prop="masseger"
        min-width="300"
        show-overflow-tooltip
      />
    </el-table>
    <Pagination
      :total="total"
      :page="pagination.page"
      @current-change="getList"
      @SizeChange="handleSizeChange"
    />
  </div>
</template>

<script>
import { parseTime } from '@/utils/index'
import { loginLog } from '@/api'
import Pagination from '@/components/paginations'
import { queryFormConfig } from './config'
export default {
  name: 'Loginlog',
  components: {
    Pagination
  },
  data() {
    return {
      queryFormConfig,
      list: [],
      pagination: {
        page: 1,
        rows: 10
      },
      total: 0,
      statusList: [
        { value: '0', label: this.translate('qydw') },
        { value: '1', label: this.translate('grfqydw') }
      ],
      filters: {},
      listLoading: true
    }
  },
  created() {
    this.getList(1)
  },
  mounted() {
    this.$nextTick(() => {
      this.$refs.table.doLayout()
    })
  },
  activated() {
    this.$nextTick(() => {
      this.$refs.table.doLayout()
    })
  },
  methods: {
    clearList() {
      this.filters = {}
      this.getList(1)
    },
    handleSizeChange(value) {
      this.pagination.rows = value
      this.getList(1)
    },
    showSource(value) {
      this.statusList.forEach(e => {
        if (e.value === value) {
          return e.label
        }
      })
    },
    getList(page) {
      this.listLoading = true
      const { filters, pagination } = this
      if (page) {
        pagination.page = page
        this.pagination.page = page
      }
      if (pagination.page === 1) {
        pagination.firstQueryTime = parseTime(new Date())
      }
      if (filters.time && filters.time.length > 0) {
        filters.makeStartTime = filters.time[0]
        filters.makeEndTime = filters.time[1]
      } else {
        filters.makeStartTime = ''
        filters.makeEndTime = ''
      }
      loginLog({ pagination, param: { ...filters } }).then(res => {
        this.listLoading = false
        if (res.errorCode === '000000') {
          this.list = res.recordList
          this.total = res.totalCount
        }
      }).catch(() => {
        this.listLoading = false
      })
    }
  }
}
</script>
